package myJs.search.detail

import myJs.myPkg.ReactRouterDOM
import org.scalajs.dom.{URLSearchParams, window}
import slinky.core.FunctionalComponent
import slinky.core.annotations.react
import myJs.Implicits._
import myJs.MainCp
import slinky.core.facade.Hooks._
import slinky.web.html._

/**
 * Created by yz on 21/1/2022
 */
@react object Cp {

  type Props = Unit
  val curPage = Detail

  val component = FunctionalComponent[Props] { props =>

    val location = ReactRouterDOM.useLocation()
    val searchParams = new URLSearchParams(location.search)
    val species = searchParams.get("species").null2Empty
    val geneName = searchParams.get("geneName").null2Empty
    val didMount = useRef(false)

    useEffect(() => {
      if (didMount.current) {
        window.location.reload(false)
      } else {
        didMount.current = true
      }
    }, List(location)
    )

    val ele = species match {
      case "Hsa" => HCp(geneName = geneName)
      case "Mmu" => MCp(geneName = geneName)
    }
    MainCp(title = curPage.titleStr)(
      div(className := "panel panel-default",
        div(className := "panel-heading",
          h3(className := "panel-title",
            s"${curPage.titleStr} - ${geneName}"
          )
        ),
        div(className := "panel-body",
          ele
        )
      )
    )

  }

  object STool {


  }

}
